rm(list = ls())

library(readstata13)
library(plm)
library(boot)
library(MASS)
library(plyr)
library(ggplot2)



#Making K-S Graph

KS_plot <- read.csv("Output/KS_Export_GGPlot.csv")

KS_plot <- ddply(KS_plot, .(Treatment),
                 transform, pos = cumsum(party_perc) - (0.5 * party_perc))

KS_plot$Treatment <- factor(KS_plot$Treatment, levels = c("Control", "Dem. Investigation", "Rep. Investigation", "Generic Criticsm"))


fill <- c("#808080", "#FFFAFA", "#DCDCDC")


stacked_bar <- ggplot() + theme_bw() + geom_bar(aes(y = party_perc, x = Treatment, fill = Partisanship), data = KS_plot,
                                                stat="identity") + geom_text(data=KS_plot, aes(x = Treatment, y = pos,
                                                                                               label = paste0(round(party_perc, digits = 2),"%")), size=4) + 
                                                labs(x="Treatment Group", y="Percentage of Respondents")+ scale_fill_manual(values=fill)
  


ggsave("Output/KS_StackedBar.pdf", plot = last_plot())
